package com.zry.study.ui.base

import android.app.Dialog
import android.content.pm.ActivityInfo
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.os.Build
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutCompat
import android.view.Window
import android.view.WindowManager
import com.zry.study.animation.RecyclerViewUtilKt
import com.zry.study.config.MyActivityManager
import com.zry.study.config.MyApplication
import com.zry.study.utils.ToastUtil


abstract class BaseActivity : AppCompatActivity() {
	var myApplication: MyApplication? = null
	var recyclerViewUtilKt: RecyclerViewUtilKt? = null
	var myActivityManager: MyActivityManager? = null
	var loadingDialog: Dialog? = null
	var viewDataBinding: ViewDataBinding? = null
	
	
	override fun onCreate(savedInstanceState: Bundle?) {
		super.onCreate(savedInstanceState)
		viewDataBinding = getDataBinding()
		
		//透明状态栏
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			val window: Window = window;
			// Translucent status bar
			window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
		}
		
		myActivityManager = MyActivityManager.getActivityManager()
		myActivityManager?.addActivity(this)
		myActivityManager?.addPermissionActivity(this)
		myApplication = MyApplication.instance
		//禁止横竖屏切换
		requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
		loadingDialog = ToastUtil.loadingDialog(this)
		
		
		initData()
	}
	
	
	private fun getDataBinding(): ViewDataBinding {
		return DataBindingUtil.setContentView(this, getLayoutId())
	}
	
	protected abstract fun getLayoutId(): Int
	protected abstract fun initData()
	
	
	protected fun toast(toastMessage: String) {
		ToastUtil.toast(this, toastMessage)
	}
	
	
	override fun onDestroy() {
		super.onDestroy()
		myActivityManager?.removePermissionActivity(this)
		myActivityManager?.finishActivity()
	}
	
}

